package sort;

import java.util.ArrayList;
import java.util.List;

/**
 * @author XY
 * @version 1.0
 * @date 2022/2/17 9:14
 * @Description
 */
public class Leet1859 {

    public static String sortSentence(String s) {
        String[] s1 = s.split(" ");
        String res = "";
        for (int i = 0; i < s1.length; i++) {
            for(int j = 0 ;j<s1.length;j++){
                if(s1[j].contains(String.valueOf(i+1))){
                    res+=" "+s1[j].substring(0,s1[j].indexOf(String.valueOf(i+1)));
                }
            }

        }
        return res.substring(1);
    }

    //创建一个新数组，字符串最后一位是几，加进新数组的下标就是几
    public static String sortSentence1(String s) {
        String[] s1 = s.split(" ");
        String[] temp = new String[s1.length];
        for (String s2 : s1) {
            temp[Integer.valueOf(s2.substring(s2.length()-1))-1] = s2.substring(0,s2.length()-1);
        }
        String res = "";
        for (String s2 : temp) {
            res+=" "+s2;
        }
        return res.substring(1);
    }

    public static void main(String[] args) {
        System.out.println(sortSentence1("is2 sentence4 This1 a3"));
    }
}
